from sqlalchemy.ext.asyncio import AsyncSession

from sqlalchemy.ext.asyncio import AsyncSession

from module_stock.dao.stat_position_dao import StatPositionDao
from module_stock.entity.vo.stat_position_vo import StatPositionPageQueryModel
from utils.association_util import process_associated_data


class StatPositionService:
    """
    股票交易统计模块服务层
    """

    @classmethod
    async def get_stat_position_list_services(
            cls, query_db: AsyncSession, query_object: StatPositionPageQueryModel, is_page: bool = False
    ):
        """
        获取股票交易统计列表信息service

        :param query_db: orm对象
        :param query_object: 查询参数对象
        :param is_page: 是否开启分页
        :return: 股票交易统计列表信息对象
        """
        stat_position_list_result = await StatPositionDao.get_stat_position_list(query_db, query_object, is_page)
        # 定义关联映射: 目标字段 -> 源数据索引
        association_mapping = {'stockName': 1}
        stat_position_list_result = process_associated_data(stat_position_list_result, association_mapping, '', is_page)

        return stat_position_list_result
